package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import bean.YeeLink;

public class getCommand extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
//		PrintWriter out = response.getWriter();
		try {
			String ss = YeeLink.doGet();
			JSONArray jsonArray = JSONArray.fromObject(ss);
			for(int i=0;i<jsonArray.size();i++){
				JSONObject obj = jsonArray.getJSONObject(i);
				//out.println(obj.getString("title")+":"+obj.getInt("last_data"));
				request.setAttribute(obj.getString("title"),obj.getInt("last_data"));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		request.setAttribute("hospitalEntitys", "true");
		//request.setAttribute("bulba", 0);
		RequestDispatcher dispatcher = request.getRequestDispatcher("./pages/command.jsp");
		dispatcher.forward(request, response);
		//PrintWriter out = response.getWriter();
		//out.print("aa");
	}
}
